package com.aiti.lulian.controller.gongxin;

import com.aiti.base.core.base.controller.WebController;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.gxmh.dto.GxmhMessageDto;
import com.aiti.lulian.gxmh.entity.GxmhMessage;
import com.aiti.lulian.gxmh.service.IGxmhMessageService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "工信门户-消息控制层")
@RestController
@RequestMapping("/gxmhMsg")
public class GxmhMessageController extends WebController {

    @Autowired
    private IGxmhMessageService gxmhMessageService;

    @ApiOperation("新增消息")
    @PostMapping
    public Message add(@RequestBody GxmhMessageDto dto) {
        dto.setCreator(findUserId());
        return gxmhMessageService.add(dto);
    }

    @ApiOperation("查询已推送的消息列表")
    @GetMapping("/list")
    public Message getList(GxmhMessageDto dto) {
        Page<GxmhMessage> page = startPage();
        List<GxmhMessage> list = gxmhMessageService.getList(page, dto);
        return Message.success(getPageResult(list, dto.getPageNum(), dto.getPageSize(), page.getTotal()));
    }

    @ApiOperation("删除消息")
    @DeleteMapping
    public Message delete(GxmhMessageDto dto) {
        return gxmhMessageService.delete(dto);
    }
}
